package com.binance.rabbitmq.config;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.util.StringUtils;

/**
 * Created by robin.wu on 2018/12/3.
 */
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
@Log4j2
@ConfigurationProperties
public class FailConfig extends AbstractConfig {

    @NestedConfigurationProperty
    private ExchangeConfig failExchange;

    @NestedConfigurationProperty
    private QueueConfig failQueue;

    private String routingKey;

    @Override
    public boolean validate() {
        log.info("Validating FailConfig...");
        boolean valid = true;

        if(failExchange == null) {
            log.error("Validating failed. FailExchange must provided for fail config.");
            valid = false;
        }

        if(failQueue == null) {
            log.error("Validating failed. FailQueue must provided for fail config.");
            valid = false;
        }

        if(StringUtils.isEmpty(routingKey)) {
            log.error("Validating failed. RoutingKey must provided for fail config.");
            valid = false;
        }

        return valid;
    }
}
